#include <algorithm>
#include <cstdio>
using namespace std;
//Trie
const int N = 100001;
int n, cnt, tot = 1, heads[N];
int d[N];
int ans = 0;
int trie[N * 33][2];

struct Edge {
	int v, nxt, w;
} e[100001];
inline void add(int u, int v, int w) {
	e[++cnt].nxt = heads[u];
	heads[u] = cnt;
	e[cnt].v = v;
	e[cnt].w = w;
}

void dfs(int x) {
	for (int i = heads[x]; i; i = e[i].nxt) {
		d[e[i].v] = d[x] ^ e[i].w;
		dfs(e[i].v);
	}
}

void insert(int x, int ptr) {
	bool tmp = 0;
	for (register int i = 30; ~i; --i) {
		tmp = (x >> i) & 1;
		if (!trie[ptr][tmp]) trie[ptr][tmp] = ++tot;
		ptr = trie[ptr][tmp];
	}
}

int query(int x, int ptr) {
	int res = 0;
	bool tm = 0;
	for (register int i = 30; ~i; --i) {
		tm = (x >> i) & 1;
		if (trie[ptr][!tm]) {
			res += (1 << i);
			ptr = trie[ptr][!tm];
		} else {
			ptr = trie[ptr][tm];
		}
	}
	return res;
}

int main() {
#ifndef ONLINE_JUDGE
#ifdef DEBUG
	freopen("testdata.in", "r", stdin);
	freopen("testdata.out", "w", stdout);
#endif
#ifndef DEBUG
	freopen("P4551.in", "r", stdin);
	freopen("P4551.out", "w", stdout);
#endif
#endif
	scanf("%d", &n);
	int u = 0, v = 0, w = 0;
	for (int i = 1; i < n; ++i) {
		scanf("%d%d%d", &u, &v, &w);
		add(u, v, w);
	}
	dfs(1);
	for (int i = 1; i <= n; ++i) {
		insert(d[i], 1);
		ans = max(ans, query(d[i], 1));
	}
	printf("%d", ans);
	return 0;
}